package com.kiln.juxingqs.adapter

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.Paint
import android.text.Layout
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import client.global.commlib.base.BaseLoadmoreAdapter
import client.global.commlib.base.BindingViewHoder
import com.bumptech.glide.RequestManager
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GoodsDetail
import com.kiln.juxingqs.api.bean.GoodsIndex
import com.kiln.juxingqs.databinding.LayoutZrppitemGoods2Binding
import com.kiln.juxingqs.databinding.LayoutZrppitemGoodsBinding
import com.kiln.juxingqs.ui.LotDeal2Activity
import com.kiln.juxingqs.ui.LotDealStatus1Activity
import com.kiln.juxingqs.utils.TextTool

class ZrppOneNewAdapter : BaseLoadmoreAdapter<GoodsIndex.Goods> {

    lateinit var goodsIndex: GoodsIndex
    var mManager: RequestManager

    constructor(context: Context, manager: RequestManager) : super(context,
        object : DiffUtil.ItemCallback<GoodsIndex.Goods>() {
            override fun areItemsTheSame(
                oldItem: GoodsIndex.Goods,
                newItem: GoodsIndex.Goods
            ): Boolean {
                return false
            }

            override fun areContentsTheSame(
                oldItem: GoodsIndex.Goods,
                newItem: GoodsIndex.Goods
            ): Boolean {
                return false
            }
        }) {
        mManager = manager
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.layout_zrppitem_goods,
                parent,
                false
            )
        )
    }

    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as LayoutZrppitemGoodsBinding
        val bean = getItem(position)
        binding.bean = bean
        binding.event = this

//        mManager.load(bean.goods_img).into(binding.img)
//
//        TextTool.getBuilder("¥").setAlign(Layout.Alignment.ALIGN_CENTER).setBold().setTextSize(10)
//            .append(bean.price.toString()).setForegroundColor(Color.parseColor("#E81837")).setBold().setTextSize(12)
//            .into(binding.tvPrice)
//        binding.tvPriceOld.apply {
//            setPaintFlags(binding.tvPriceOld.getPaintFlags() or Paint.STRIKE_THRU_TEXT_FLAG)
//        }

//        var position = holder.layoutPosition
////        LogUtils.i(position)
//        if (position % 2 == 0) {
//            position = 1
//        } else if (position == 1) {
//            position = 0
//        }
//
//        binding.apply {
//            when (position) {
//                0 -> {
//                    tvLabel.isVisible = true
//                    tvLabel2.isVisible = false
//                }
//                1 -> {
//                    tvLabel.isVisible = true
//                    tvLabel2.isVisible = true
//                }
//                6 -> {
//                    tvLabel.isVisible = false
//                    tvLabel2.isVisible = false
//                }
//                else -> {
//                    tvLabel.isVisible = true
//                    tvLabel2.isVisible = false
//                }
//            }
//        }

//        if (bean.name.equals("振中慈缘+")) {
//            binding.bbb.text = "50.00"
//        } else {
//            binding.bbb.text = "200.00"
//        }

    }

    fun submitData(list: MutableList<GoodsIndex.Goods?>, goodsIndex: GoodsIndex) {
        this.goodsIndex = goodsIndex
        if (list.get(0) != null)
            submitList(list)
    }


    fun itemClick(bean: GoodsIndex.Goods) {
        if (bean.deal_status.equals("1")) {
            context.startActivity(Intent(context, LotDealStatus1Activity::class.java).apply {
                putExtra("goods_id", "${bean.goods_id}")
            })
        } else
            context.startActivity(Intent(context, LotDeal2Activity::class.java).apply {
                putExtra("goods_id", "${bean.goods_id}")

//            if (goodsIndex != null) {
//                goodsIndex.banner_list?.let {
//                    putExtra("banner_list", goodsIndex.banner_list as ArrayList<GoodsDetail.Banner>)
//                }
//                goodsIndex.goods_list?.let {
//                    putExtra("detail_list", goodsIndex.goods_list as ArrayList<GoodsDetail.Detail>)
//                }
//            }


            })

    }


}